package com.farmer.machinery.controller;

import com.farmer.common.entity.Machinery;
import com.farmer.common.result.Result;
import com.farmer.machinery.service.MachineryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/machinery")
public class MachineryController {
    @Autowired
    private MachineryService machineryService;

    @GetMapping("/list")
    public Result<?> list(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "10") Integer pageSize,
                          @RequestParam(required = false) String name,
                          @RequestParam(required = false) String type,
                          @RequestParam(required = false) String status) {
        return machineryService.list(pageNum, pageSize, name, type, status);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody Machinery machinery) {
        return machineryService.add(machinery);
    }

    @PutMapping("/update")
    public Result<?> update(@RequestBody Machinery machinery) {
        return machineryService.update(machinery);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        return machineryService.delete(id);
    }

    @GetMapping("/{id}")
    public Result<?> detail(@PathVariable Long id) {
        return machineryService.detail(id);
    }
} 